//
//  JWelcomeVC.swift
//  JMicroBlog
//
//  Created by Jason on 21/5/15.
//  Copyright (c) 2015 Shepherd. All rights reserved.
//

import UIKit
import SDWebImage
class JWelcomeVC: UIViewController {

    // 头像与底部的距离
    @IBOutlet weak var bottomCons: NSLayoutConstraint!
    
    // 头像
    @IBOutlet weak var iconView: UIImageView!
    
    // 欢迎文字
    @IBOutlet weak var welcomeLabel: UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 判断是否存在用户账户信息
        if let urlString = sharedUserInfo?.avatar_large {
            iconView.sd_setImageWithURL(NSURL(string: urlString))
        }
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        // 修改约束
        bottomCons.constant = view.bounds.height - bottomCons.constant
        self.welcomeLabel.alpha = 0.0
        UIView.animateWithDuration(1.5, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 5.0, options: nil, animations: {
            self.view.layoutIfNeeded()
        }) {  _ in
            UIView.animateWithDuration(0.5, animations: {
                self.welcomeLabel.alpha = 1.0
            }, completion: { _ in
                NSNotificationCenter.defaultCenter().postNotificationName(JExchangeRootVCNotification, object: "JMain")
            })
        }
    }
}
